<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<title>仿有道词典</title>
<link href="css/mui.css" rel="stylesheet"/>
<link href="css/style.css" rel="stylesheet"/>
</head>
<body>
<header class="mui-bar mui-bar-nav bg-red">
    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
    <h1 class="mui-title" id="title"></h1>
</header>
<div class="mui-content" id="newsContent"></div>
<div class="newsFooter">
	<div class="share" id="share"><img src="images/share.png"/></div>
</div>
<script src="js/mui.min.js"></script>	
<script src="js/h.js"></script>	
<script type="text/javascript" charset="utf-8">
mui.init();
var news;
mui.plusReady(function(){
	var _self = plus.webview.currentWebview();
	console.log(_self.newsId)
	mui.getJSON(
		'http://hoa.hcoder.net/index.php?user=hcoder&pwd=hcoder&m=info&id='+_self.newsId,
		function(res){
			news=res;
			//console.log(JSON.stringify(res));
			h("#title").html(res.title);
			h("#newsContent").html(res.content)
		}
	)
})
h('#share').tap(function(){
    var actionbuttons = [{title : "微信好友"}, {title : "朋友圈"}];
    var actionstyle   = {title : "请选择分享类型", cancel : "取消", buttons : actionbuttons};
    plus.nativeUI.actionSheet(actionstyle, function(e){
        if(e.index >=1){
            shareNow(e.index);
        }
    });
});
var sharewx = null;
function shareNow(type){
    plus.share.getServices(function(services){
        for(var i in services){
            if('weixin' == services[i].id){sharewx=services[i];}
        }
        if(sharewx == null){mui.toast('请先安装微信'); return false;}
        var msg = {
            content : news.title,
            href : "http://www.hcoder.net/info/id"+news.id
        }
        if(type == 2){
            msg.extra = {scene:"WXSceneTimeline"}
        }else{
            msg.extra = {scene:"WXSceneSession"}
        }
        sharewx.send(msg, function(){mui.toast('分享成功')},function(){mui.toast('分享失败或用户取消');});
    });
}
</script>
</body>
</html>